package com.wangsd.web.face.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wangsd.web.face.entity.Member;
import com.wangsd.web.face.entity.MemberAccountDetail;
import com.wangsd.web.face.mapper.MemberAccountDetailMapper;
import com.wangsd.web.face.mapper.MemberMapper;
import com.wangsd.web.face.service.MemberAccountDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangsd.web.miniapp.entity.WxPay;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author generator
 * @since 2019-10-31
 */
@Service
public class MemberAccountDetailServiceImpl extends ServiceImpl<MemberAccountDetailMapper, MemberAccountDetail> implements MemberAccountDetailService {

    @Resource
    MemberAccountDetailMapper memberAccountDetailMapper;

    @Resource
    MemberMapper memberMapper;

    @Override
    public IPage<MemberAccountDetail> selectList(Integer pageNum, Integer pageSize, WxPay params) {
        Member member = memberMapper.selectOne(new QueryWrapper<Member>()
                .eq("mobile", params.getMobile())
                .eq("merchant_id", params.getMerchantId()));
        if (member == null) {
            return null;
        }
        Page<MemberAccountDetail> page = new Page<>(pageNum, pageSize);
        QueryWrapper<MemberAccountDetail> queryWrapper = new QueryWrapper<>();
        if (params.getType() != null) {
            queryWrapper.eq("type", params.getType());
        }
        queryWrapper.eq("member_id", member.getId());
        IPage<MemberAccountDetail> resultIPage = memberAccountDetailMapper.selectPage(page, queryWrapper);
        return resultIPage;
    }
}
